const app = getApp()
const text = require('../../../../common/util/text.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    explain_info_list:[],
    name:'',
    show:false,
    xPageReady:true,
    scroll:false
  },
  onPageScroll(e){
    if(e.scrollTop>88){
      this.setData({
        scroll:true
      })
    }else{
      this.setData({
        scroll:false
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that =this
    that.setData({
      name:options.name
    })
    that.xInit()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  onHide:function(){
    
    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      show:false
    })
    // wx.setNavigationBarTitle({
    //   title: '带状疤疹神经痛舒缓训练',
    // })
  },
  xToSet:function(){
    // !this.data.show
    this.setData({
      show:true
    })
  },
  xInit:async function(){
    let that =this
    await wx.cloud.callFunction({
      name: 'soothing_exercise',
      data: {
        action: "get_explain_info"
      }
    }).then(res => {
        res.result[0].announcements = text.text(res.result[0].announcements)
        that.setData({
          explain_info_list:res.result
        })
    })

    await wx.cloud.callFunction({
      name: 'soothing_exercise',
      data: {
        action: "get_topics"
      }
     }).then(res => {
        that.setData({
          list:res.result,
        
        })
     })

     that.setData({
      xPageReady:false
     })
  },
  xToVideo:function(e){
    let that = this
    let params = e.currentTarget.dataset
    wx.navigateTo({
      url: '/subtool/pages/productother/video/index',
      success: function(res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('xToVideo', params)
      }
    })
  },
  xToDetail:function(e){
    let that =this
    let params = e.currentTarget.dataset
    if(!app.globalData.product_buy && params.is_pay){
      wx.showModal({
        title: "提示",
        content: "解锁完整版可使用该功能",
        confirmText:'去解锁',
        success (res) {
          if (res.confirm) {
            that.xToProductde()
          }
        }
      })
      
    }else{
      wx.navigateTo({
        url: '/subtool/pages/productother/detail/index?id='+params.id,
      })
    }
  },
    // 产品详情
    xToProductde:function(){
      let that =this
      if(!app.globalData.user.phone_number){
        let path = '/pages/navigation/using/index'
        wx.navigateTo({
          url: '/pages/navigation/login/index?path='+path,
        })
      }else{
        wx.navigateTo({
          url: '/subsale/pages/product/index/index?choose=true&id=26da8e4962b93a6000ec7c3d68d9d3eb'
        })
      }
    },
    toback:function(){
      wx.navigateBack({
        delta:1
      })
    },
    xWarning:function(){
      wx.showToast({
        title: '该模块即将上线，敬请期待',
        icon:'none'
      })
    },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      path:'/pages/navigation/index/index'
    }
  }
})